home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-08 | 3.2 KB | 145 lines | [TEXT/MPCC] |
- # Based on the file "setjmp.s" from Metrowerks CodeWarrior 5. The original
- # "setjmp.s" is copyright © 1993 Metrowerks Inc.
-
- # Assembly language routines for saving and restoring
- # registers, for use from the PowerPC version of Thread
- # Library. There are two functions:
- #
- # ThreadRegistersPPCSave similar to setjmp;
- # ThreadRegistersPPCRestore similar to longjmp.
- #
- # The pointer passed to ThreadRegistersPPCSave and ThreadRegistersPPCRestore
- # should be defined as an array of long integers. See the file "regppc.h" for
- # the actual definitions.
- #
- # The pointer passed to ThreadRegistersPPCSave and ThreadRegistersPPCRestore
- # corresponds to the following structure.
- #
- # typedef struct ThreadRegistersPPCType {
- # unsigned long unused; // 0: unused
- # unsigned long PC; // 4: saved PC
- # unsigned long CR; // 8: saved CR
- # unsigned long SP; // 12: saved SP
- # unsigned long RTOC; // 16: saved RTOC
- # unsigned long GPRs[19]; // 20: saved r13-r31
- # double FPRs[18]; // 96: saved fp14-fp31
- # double FPSCR; //240: saved FPSCR
- # };
- #
- # To assemble this file:
- #
- # ppcasm regppc.s -o regppc.xcoff
- #
-
- dialect powerpc
-
- #
- # Export function names.
- #
-
- toc
-
- csect ThreadRegistersPPCSave[DS]
- export ThreadRegistersPPCSave[DS]
- dc.l .ThreadRegistersPPCSave[PR]
- dc.l TOC[TC0]
-
- csect ThreadRegistersPPCRestore[DS]
- export ThreadRegistersPPCRestore[DS]
- dc.l .ThreadRegistersPPCRestore[PR]
- dc.l TOC[TC0]
-
- #
- # ThreadRegistersPPCSave
- #
- # On entry:
- #
- # R3 points to a ThreadRegistersPPCType structure.
- #
- # On exit:
- #
- # R3 is 0.
- #
- csect .ThreadRegistersPPCSave[PR]
- export .ThreadRegistersPPCSave[PR]
- mflr r5
- mfcr r6
- stw r5,4(r3) # save PC (LR)
- stw r6,8(r3) # save CR
- stw SP,12(r3) # save SP
- stw RTOC,16(r3) # save RTOC
- stmw r13,20(r3) # save r13-r31
- mffs fp0
- stfd fp14,96(r3) # save fp14-fp31
- stfd fp15,104(r3)
- stfd fp16,112(r3)
- stfd fp17,120(r3)
- stfd fp18,128(r3)
- stfd fp19,136(r3)
- stfd fp20,144(r3)
- stfd fp21,152(r3)
- stfd fp22,160(r3)
- stfd fp23,168(r3)
- stfd fp24,176(r3)
- stfd fp25,184(r3)
- stfd fp26,192(r3)
- stfd fp27,200(r3)
- stfd fp28,208(r3)
- stfd fp29,216(r3)
- stfd fp30,224(r3)
- stfd fp31,232(r3)
- stfd fp0,240(r3) # save FPSCR
- li r3,0
- blr
-
- # end ThreadRegistersPPCSave.
-
- #
- # ThreadRegistersPPCRestore
- #
- # On entry:
- #
- # R3 points to a ThreadRegistersPPCType structure
- # R4 contains the return value.
- #
- # On exit:
- #
- # R3 contains 1 if R4 was 0, otherwise it contains the value from R4.
- #
- csect .ThreadRegistersPPCRestore[PR]
- export .ThreadRegistersPPCRestore[PR]
- lwz r5,4(r3)
- lwz r6,8(r3)
- mtlr r5 # restore PC (LR)
- mtcrf 255,r6 # restore CR
- lwz SP,12(r3) # restore SP
- lwz RTOC,16(r3) # restore RTOC
- lmw r13,20(r3) # restore r13-r31
- lfd fp14,96(r3) # restore fp14-fp31
- lfd fp15,104(r3)
- lfd fp16,112(r3)
- lfd fp17,120(r3)
- lfd fp18,128(r3)
- lfd fp19,136(r3)
- lfd fp20,144(r3)
- lfd fp21,152(r3)
- lfd fp22,160(r3)
- lfd fp23,168(r3)
- lfd fp24,176(r3)
- lfd fp25,184(r3)
- lfd fp26,192(r3)
- lfd fp27,200(r3)
- lfd fp28,208(r3)
- lfd fp29,216(r3)
- lfd fp30,224(r3)
- lfd fp0,240(r3)
- lfd fp31,232(r3)
- cmpwi r4,0
- mr r3,r4
- mtfsf 255,fp0 # restore FPSCR
- bnelr # return value in R4
- li r3,1 # return 1
- blr
-
- # end ThreadRegistersPPCRestore.
-